<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="身份证号，关联考生信息表" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号，关联考生信息表"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专科院校ID" prop="vocationalCollegeId">
        <el-input
          v-model="queryParams.vocationalCollegeId"
          placeholder="请输入专科院校ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专科专业ID" prop="vocationalMajorId">
        <el-input
          v-model="queryParams.vocationalMajorId"
          placeholder="请输入专科专业ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考生类型ID" prop="candidateTypeId">
        <el-input
          v-model="queryParams.candidateTypeId"
          placeholder="请输入考生类型ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通知书邮寄地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入通知书邮寄地址"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通知书收件人" prop="recipientName">
        <el-input
          v-model="queryParams.recipientName"
          placeholder="请输入通知书收件人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮编" prop="postalCode">
        <el-input
          v-model="queryParams.postalCode"
          placeholder="请输入邮编"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考点盟市ID" prop="examCenterCityId">
        <el-input
          v-model="queryParams.examCenterCityId"
          placeholder="请输入考点盟市ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报考专业ID" prop="examMajorId">
        <el-input
          v-model="queryParams.examMajorId"
          placeholder="请输入报考专业ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="志愿院校ID" prop="volunteerCollegeId">
        <el-input
          v-model="queryParams.volunteerCollegeId"
          placeholder="请输入志愿院校ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="志愿专业ID" prop="volunteerMajorId">
        <el-input
          v-model="queryParams.volunteerMajorId"
          placeholder="请输入志愿专业ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['baoming:TBregistration:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['baoming:TBregistration:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['baoming:TBregistration:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['baoming:TBregistration:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="TBregistrationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报名ID" align="center" prop="id" />
      <el-table-column label="身份证号，关联考生信息表" align="center" prop="idNumber" />
      <el-table-column label="专科院校ID" align="center" prop="vocationalCollegeId" />
      <el-table-column label="专科专业ID" align="center" prop="vocationalMajorId" />
      <el-table-column label="考生类型ID" align="center" prop="candidateTypeId" />
      <el-table-column label="通知书邮寄地址" align="center" prop="address" />
      <el-table-column label="是否获得证书" align="center" prop="isCertificateIssued" />
      <el-table-column label="通知书收件人" align="center" prop="recipientName" />
      <el-table-column label="邮编" align="center" prop="postalCode" />
      <el-table-column label="考点盟市ID" align="center" prop="examCenterCityId" />
      <el-table-column label="报考专业ID" align="center" prop="examMajorId" />
      <el-table-column label="志愿院校ID" align="center" prop="volunteerCollegeId" />
      <el-table-column label="志愿专业ID" align="center" prop="volunteerMajorId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['baoming:TBregistration:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['baoming:TBregistration:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专升本考试报名对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="TBregistrationRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="身份证号，关联考生信息表" prop="idNumber">
          <el-input v-model="form.idNumber" placeholder="请输入身份证号，关联考生信息表" />
        </el-form-item>
        <el-form-item label="专科院校ID" prop="vocationalCollegeId">
          <el-input v-model="form.vocationalCollegeId" placeholder="请输入专科院校ID" />
        </el-form-item>
        <el-form-item label="专科专业ID" prop="vocationalMajorId">
          <el-input v-model="form.vocationalMajorId" placeholder="请输入专科专业ID" />
        </el-form-item>
        <el-form-item label="考生类型ID" prop="candidateTypeId">
          <el-input v-model="form.candidateTypeId" placeholder="请输入考生类型ID" />
        </el-form-item>
        <el-form-item label="通知书邮寄地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入通知书邮寄地址" />
        </el-form-item>
        <el-form-item label="通知书收件人" prop="recipientName">
          <el-input v-model="form.recipientName" placeholder="请输入通知书收件人" />
        </el-form-item>
        <el-form-item label="邮编" prop="postalCode">
          <el-input v-model="form.postalCode" placeholder="请输入邮编" />
        </el-form-item>
        <el-form-item label="考点盟市ID" prop="examCenterCityId">
          <el-input v-model="form.examCenterCityId" placeholder="请输入考点盟市ID" />
        </el-form-item>
        <el-form-item label="报考专业ID" prop="examMajorId">
          <el-input v-model="form.examMajorId" placeholder="请输入报考专业ID" />
        </el-form-item>
        <el-form-item label="志愿院校ID" prop="volunteerCollegeId">
          <el-input v-model="form.volunteerCollegeId" placeholder="请输入志愿院校ID" />
        </el-form-item>
        <el-form-item label="志愿专业ID" prop="volunteerMajorId">
          <el-input v-model="form.volunteerMajorId" placeholder="请输入志愿专业ID" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="TBregistration">
import { listTBregistration, getTBregistration, delTBregistration, addTBregistration, updateTBregistration } from "@/api/baoming/TBregistration";

const { proxy } = getCurrentInstance();

const TBregistrationList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    idNumber: null,
    vocationalCollegeId: null,
    vocationalMajorId: null,
    candidateTypeId: null,
    address: null,
    isCertificateIssued: null,
    recipientName: null,
    postalCode: null,
    examCenterCityId: null,
    examMajorId: null,
    volunteerCollegeId: null,
    volunteerMajorId: null
  },
  rules: {
    idNumber: [
      { required: true, message: "身份证号，关联考生信息表不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询专升本考试报名列表 */
function getList() {
  loading.value = true;
  listTBregistration(queryParams.value).then(response => {
    TBregistrationList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    idNumber: null,
    vocationalCollegeId: null,
    vocationalMajorId: null,
    candidateTypeId: null,
    address: null,
    isCertificateIssued: null,
    recipientName: null,
    postalCode: null,
    examCenterCityId: null,
    examMajorId: null,
    volunteerCollegeId: null,
    volunteerMajorId: null
  };
  proxy.resetForm("TBregistrationRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加专升本考试报名";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getTBregistration(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改专升本考试报名";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["TBregistrationRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateTBregistration(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addTBregistration(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除专升本考试报名编号为"' + _ids + '"的数据项？').then(function() {
    return delTBregistration(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('baoming/TBregistration/export', {
    ...queryParams.value
  }, `TBregistration_${new Date().getTime()}.xlsx`)
}

getList();
</script>
